package com.cnfangmao.masterdata.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnfangmao.masterdata.dao.EnumValueDao;
import com.cnfangmao.masterdata.dto.EnumValueDto;
import com.cnfangmao.masterdata.dto.GeneralSearchDto;
import com.cnfangmao.masterdata.model.EnumValue;
import com.cnfangmao.masterdata.service.EnumValueService;
import com.cnfangmao.masterdata.vo.EnumValueVo;
import com.cnfangmao.masterdata.vo.GeneralPageVo;

/**
 * <p>
 * 字段枚举值 服务实现类
 * </p>
 *
 * @author chenxd
 * @since 2020-04-14
 */
@Service
public class EnumValueServiceImpl extends ServiceImpl<EnumValueDao, EnumValue> implements EnumValueService {

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.EnumValueService#getEnumValueById(java.lang.String)
	 */
	@Override
	public EnumValueVo getEnumValueById(String valueId) {
		return this.baseMapper.queryEnumValueById(valueId);
	}

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.EnumValueService#getEnumValueByCondition(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public EnumValueVo getEnumValueByCondition(String typeId, String valueCode, String valueName) {
		return this.baseMapper.queryEnumValueByCondition(typeId, valueCode, valueName);
	}
	
	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.EnumValueService#getAllEnumValues()
	 */
	@Override
	public List<EnumValueVo> getAllEnumValues() {
		return this.baseMapper.queryAllEnumValues();
	}

	/* (non-Javadoc)
	 * @see com.cnfangmao.masterdata.service.EnumValueService#getEnumValuesByPage(com.cnfangmao.masterdata.dto.GeneralSearchDto)
	 */
	@Override
	public GeneralPageVo<EnumValueVo> getEnumValuesByPage(GeneralSearchDto<EnumValueDto> searchDto) {
		IPage<EnumValueVo> page = new Page<EnumValueVo>(searchDto.getPageNo(), searchDto.getPageSize());
		QueryWrapper<EnumValueVo> queryWrapper = new QueryWrapper<EnumValueVo>();
		queryWrapper.like(!StringUtils.isEmpty(searchDto.getConditions().getValueCode()), "ev.VALUE_CODE", searchDto.getConditions().getValueCode());
		queryWrapper.like(!StringUtils.isEmpty(searchDto.getConditions().getValueName()), "ev.VALUE_NAME", searchDto.getConditions().getValueName());
		queryWrapper.orderByDesc("ev.MODIFIED_ON");
		
		IPage<EnumValueVo> pageRS = this.baseMapper.queryEnumValuesByPage(page, queryWrapper);
		
		GeneralPageVo<EnumValueVo> pageVo = new GeneralPageVo<EnumValueVo>();
		pageVo.setPageNo(pageRS.getCurrent());
		pageVo.setPageSize(pageRS.getSize());
		pageVo.setTotalCount(pageRS.getTotal());
		pageVo.setRecords(pageRS.getRecords());
		
		return pageVo;
	}

}
